/******************************************************************************
Copyright:
2009 Jens Collin (jens.collin@dinomin.com)

This file is part of Envox Decompiler.

Envox Decompiler is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Envox Decompiler is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with KitchenOS.  If not, see <http://www.gnu.org/licenses/>.

******************************************************************************/
using System;

namespace EnvoxDecompiler
{
	/// <summary>
	/// Summary description for Block_EventCheck.
	/// </summary>
	public class Block_EventCheck : Block
	{


		public override TYPE GetBlockType()
		{
			return TYPE.EventCheck;
		}


		public override string GetXML(int x, int y)
		{
			Trace.Debug("Block_EventCheck::GetXML Started.");	

			string xml = "\t\t\t";
			// <ErrorCheck name="EventCheck" rect="X 32 128 78"...
            xml += "<ErrorCheck name=\"EventCheck\" rect=\"" + x + " " + y + " 128 78\"";
			//  ...description="DESC"...
			xml += GetDescriptionXML();
			//  ...clearDTMF="_clearDTMFBuffer"...
			xml += GetClearDTMFXML();
			// ...minUserLevel="_userLevel"
			xml += GetMinUserLevelXML();
			// ...cpMessage=""...
			xml += GetControlPanelMessageXML();
			// finish the line../>
			xml += ">\r\n";
			// This block is special and need no input id, so don't use the
			// GetInputsXML() call.
			// <Inputs>
			xml += "\t\t\t\t<Inputs>\r\n";
			// <Input name=""/>
			xml += "\t\t\t\t\t<Input name=\"\"/>\r\n";
			// </Inputs>
			xml += "\t\t\t\t</Inputs>\r\n";
			
			// <Outputs>
			xml += GetOutputsXML();

			// <Logs>
			xml += GetLogsXML();
			
			// <Errors/>
			xml += GetHandledErrorsXML_EventCheckSpecial();

			// </ErrorCheck>
			xml += "\t\t\t</ErrorCheck>\r\n";
			return xml;
		}


		public Block_EventCheck(byte[] rawData) : base(rawData)
		{
			Trace.Debug("Block_EventCheck created.");

			outputErrorIds.Add(new BlockOutput(OUTPUT.Next, 0));
			outputErrorIds.Add(new BlockOutput(OUTPUT.Append, 87));
			outputErrorIds.Add(new BlockOutput(OUTPUT.BadInput, 77));
			outputErrorIds.Add(new BlockOutput(OUTPUT.BadOutput, 78));
			outputErrorIds.Add(new BlockOutput(OUTPUT.CallError, 46));
			outputErrorIds.Add(new BlockOutput(OUTPUT.CantSetVariable, 80));
			outputErrorIds.Add(new BlockOutput(OUTPUT.Compare, 30));
			outputErrorIds.Add(new BlockOutput(OUTPUT.ConfDestroyed, 127));
			outputErrorIds.Add(new BlockOutput(OUTPUT.ConnectFailed, 31));
			outputErrorIds.Add(new BlockOutput(OUTPUT.Copy, 58));
			outputErrorIds.Add(new BlockOutput(OUTPUT.Create, 55));
			outputErrorIds.Add(new BlockOutput(OUTPUT.CreditOut, 17));
			outputErrorIds.Add(new BlockOutput(OUTPUT.DbAuthorize, 33));
			outputErrorIds.Add(new BlockOutput(OUTPUT.DbFailed, 35));
			outputErrorIds.Add(new BlockOutput(OUTPUT.DbFieldType, 42));
			outputErrorIds.Add(new BlockOutput(OUTPUT.DbLocked, 32));
			outputErrorIds.Add(new BlockOutput(OUTPUT.DbSQLExpr, 52));
			outputErrorIds.Add(new BlockOutput(OUTPUT.DbTimeout, 34));
			outputErrorIds.Add(new BlockOutput(OUTPUT.DDEReceived, 70));
			outputErrorIds.Add(new BlockOutput(OUTPUT.Delete, 56));
			outputErrorIds.Add(new BlockOutput(OUTPUT.Disconnect, 15));
			outputErrorIds.Add(new BlockOutput(OUTPUT.DiskFull, 67));
			outputErrorIds.Add(new BlockOutput(OUTPUT.Execute, 88));
			outputErrorIds.Add(new BlockOutput(OUTPUT.Exit, 18));
			outputErrorIds.Add(new BlockOutput(OUTPUT.ExprVal, 28));
			outputErrorIds.Add(new BlockOutput(OUTPUT.FaxRecvTone, 72));
			outputErrorIds.Add(new BlockOutput(OUTPUT.FaxSendTone, 71));
			outputErrorIds.Add(new BlockOutput(OUTPUT.FuncFailed, 79));
			outputErrorIds.Add(new BlockOutput(OUTPUT.HookFlash, 126));
			outputErrorIds.Add(new BlockOutput(OUTPUT.IEReceived, 157));
			outputErrorIds.Add(new BlockOutput(OUTPUT.InvalidParam, 53));
			outputErrorIds.Add(new BlockOutput(OUTPUT.InvalidVarType, 22));
			outputErrorIds.Add(new BlockOutput(OUTPUT.ModeChange, 19));
			outputErrorIds.Add(new BlockOutput(OUTPUT.ModemTone, 84));
			outputErrorIds.Add(new BlockOutput(OUTPUT.Move, 86));
			outputErrorIds.Add(new BlockOutput(OUTPUT.NoAuthorization, 93));
			outputErrorIds.Add(new BlockOutput(OUTPUT.NoDLLFile, 74));
			outputErrorIds.Add(new BlockOutput(OUTPUT.NoDLLFunc, 75));
			outputErrorIds.Add(new BlockOutput(OUTPUT.NoMemory, 76));
			outputErrorIds.Add(new BlockOutput(OUTPUT.NotFound_1, 92));
			outputErrorIds.Add(new BlockOutput(OUTPUT.Notify, 98));
			outputErrorIds.Add(new BlockOutput(OUTPUT.OpBreak, 16));
			outputErrorIds.Add(new BlockOutput(OUTPUT.PlayError, 25));
			outputErrorIds.Add(new BlockOutput(OUTPUT.Record, 23));
			outputErrorIds.Add(new BlockOutput(OUTPUT.RecParams, 24));
			outputErrorIds.Add(new BlockOutput(OUTPUT.ReleaseCall, 26));
			outputErrorIds.Add(new BlockOutput(OUTPUT.Rename, 57));
			outputErrorIds.Add(new BlockOutput(OUTPUT.Restart, 20));
			outputErrorIds.Add(new BlockOutput(OUTPUT.Ring, 125));
			outputErrorIds.Add(new BlockOutput(OUTPUT.SetVariable, 29));
			outputErrorIds.Add(new BlockOutput(OUTPUT.SQLFailed, 168));
			outputErrorIds.Add(new BlockOutput(OUTPUT.UserLevel, 68));
			outputErrorIds.Add(new BlockOutput(OUTPUT.UUIReceived, 156));
			outputErrorIds.Add(new BlockOutput(OUTPUT.WaitCall, 27));

			_currentPos += 4;
			int outputs = _rawData[_currentPos];
			Trace.Debug("EventCheck special outputs: " + outputs);

			_currentPos += 4;

			// call base class output reader.
			ReadOutputs(outputs);
		}
	}
}
